package com.ibm.spatiotemp.server.datamodel.gpsdata.fake;

import java.text.ParseException;

import org.apache.log4j.Logger;

import com.ibm.spatiotemp.server.datamodel.gpsdata.TSPoint;
import com.ibm.spatiotemp.server.datamodel.gpsdata.TSPointResultSet;
import com.ibm.spatiotemp.tools.DateParser;

public class FakeTSPointResultSet extends TSPointResultSet {

	public static Logger logger = Logger.getLogger(FakeTSPointResultSet.class);
	
	protected int cur_cursor = 0;
	public FakeTSPointResultSet()
	{
		cur_cursor = 0;
	}
	
	public static String[] test_gps_data = {
		"2008-02-02 13:34:06 116.40061 39.90605",
		"2008-02-02 13:39:07 116.40121 39.9139",
		"2008-02-02 13:40:55 116.40117 39.91159",
		"2008-02-02 13:44:09 116.39245 39.90635",
		"2008-02-02 13:49:10 116.36999 39.90594",
		"2008-02-02 13:54:12 116.34526 39.90589",
		"2008-02-02 15:10:00 116.34526 39.90589",
		"2008-02-02 16:30:00 116.42000 40.10000",
		"2008-02-02 17:10:10 116.40100 39.90700",
		"2008-02-02 17:15:30 116.40100 39.90700",
		"2008-02-02 17:20:00 116.40200 39.90800",
		"2008-02-02 18:40:00 116.40201 39.90801"
	};
	public static final int data_size = 12;
	public static final String movingid = "movobj1";
	@Override
	public void close() throws Exception {
	}

	@Override
	public TSPoint getNext() throws Exception{
		if(cur_cursor < data_size)
		{
			String[] splits = test_gps_data[cur_cursor].split(" ");
			String datestring = splits[0] + " " + splits[1];
			long ts = -1L;
			try {
				ts = DateParser.getTimestamp(datestring);
			} catch (ParseException e) {
				logger.error(e.getMessage());
			}
			double x = Double.parseDouble(splits[2]);
			double y = Double.parseDouble(splits[3]);
			++cur_cursor;
			return new TSPoint(movingid,x,y,ts);
		}
		else
			return null;
	}

}
